import 'package:bpb/framework/custom/ext_widget/widget_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:url_launcher/url_launcher.dart';

import '../framework/utils/sized_box_util.dart';

Widget createDataSourceAndDisclaimer() {
  // bool useAsMedical=false;
  // if(useAsMedical==false){
  //   return sb.z();
  // }

  return Container(
    margin: EdgeInsets.only(left: 20.w, right: 20.w),
    padding: EdgeInsets.all(10.w),
    decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(15.r)), border: Border.fromBorderSide(BorderSide(color: Colors.red, width: 1))),
    child: Column(
      children: [
        Offstage(
          offstage: true,
          child: Column(
            children: [
              sb.h(10.h),

              Row(children: [Text("Data source", style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 14.sp, color: Color(0xff333333)))]),
              sb.h(10.h),
              Row(
                children: [
                  Image.asset("images/heart_assoiation.png", width: 40.w),
                  sb.w(10.w),
                  Text(
                    "American Heart Association",
                    style: GoogleFonts.poppins(fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xff2571FF), decoration: TextDecoration.underline),
                  ),
                ],
              ).prop(
                onTap: () {
                  openWebUrl("https://www.heart.org/en/");
                },
              ),
              sb.h(10.h),
            ],
          ),
        ),

        Row(children: [Text("Disclaimer", style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 14.sp, color: Color(0xff333333)))]),
        sb.h(10.h),
        Container(
          child: Text(
            "This app is intended solely for personal record-keeping. It does not measure or monitor vital signs, and it is not a medical device. Please consult a healthcare provider for medical advice.",
            style: GoogleFonts.poppins(fontWeight: FontWeight.w400, color: Color(0xff333333), fontSize: 14.sp),
          ),
        ),
        sb.h(20.h),
      ],
    ),
  );
}

Future<void> openWebUrl(String url) async {
  final Uri uri = Uri.parse(url);

  if (await canLaunchUrl(uri)) {
    await launchUrl(
      uri,
      mode: LaunchMode.externalApplication, // 在外部浏览器中打开
    );
  } else {}
}
